using System;
using System.Windows.Forms;
using SVNClean.Modules;

namespace SVNClean.Windows {
    public partial class frm_SvnNames : DevExpress.XtraEditors.XtraForm {
        /// <summary>
        /// Initializes a new instance of the <see cref="frm_SvnNames"/> class.
        /// </summary>
        public frm_SvnNames() {
            InitializeComponent();
        }

        #region "[rgn] Control Events "
        private void btnAdd_Click(object sender, EventArgs e) {
            if (txtName.Text.Length > 0) {
                if (!SvnDirectoryNames.Names.Contains(txtName.Text)) {
                    SvnDirectoryNames.Names.Add(txtName.Text);
                    SvnDirectoryNames.SaveList();
                    LoadFolders();
                }
            }
        }
        private void btnDeleteAll_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) {
            if (MessageBox.Show("Are you shure?", "Delete All", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
                == DialogResult.Yes) {
                SvnDirectoryNames.Names.Clear();
                SvnDirectoryNames.SaveList();
                LoadFolders();
            }
        }
        private void btnDeleteChecked_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) {
            var names = lstSvnFolders.CheckedIndices;
            foreach (int indice in names) {
                SvnDirectoryNames.Names.Remove(lstSvnFolders.Items[indice].Value.ToString());
            }
            SvnDirectoryNames.SaveList();
            LoadFolders();
        }
        #endregion

        /// <summary>
        /// Handles the Load event of the frm_SvnNames control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void frm_SvnNames_Load(object sender, EventArgs e) {
            LoadFolders();
            txtName.Focus();
        }

        /// <summary>
        /// Loads the folders.
        /// </summary>
        public void LoadFolders() {
            lstSvnFolders.Items.Clear();
            foreach (var name in SvnDirectoryNames.Names) {
                lstSvnFolders.Items.Add(name);
            }
            lstSvnFolders.SelectedIndex = -1;
            txtName.Text = "";
            txtName.Focus();
        }
        
    }
}